package org.foj.model;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.appfuse.model.BaseObject;
import org.codehaus.xfire.aegis.type.java5.XmlElement;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;

/**
 * @author jeremy anderson
 */
@Entity
public class Comment extends BaseObject implements Serializable {

  private Long id;
  private Issue issue;
  private String author;
  private Date createdDate;
  private String commentText;

  @Id
  @GeneratedValue(strategy = GenerationType.AUTO)
  public Long getId() {
    return id;
  }

  public void setId(Long id) {
    this.id = id;
  }

  @ManyToOne(fetch = FetchType.EAGER)
  public Issue getIssue() {
    return issue;
  }

  public void setIssue(Issue issue) {
    this.issue = issue;
  }

  public String getAuthor() {
    return author;
  }

  public void setAuthor(String author) {
    this.author = author;
  }

  @XmlElement(minOccurs = "0", nillable = true)
  public Date getCreatedDate() {
    return createdDate;
  }

  public void setCreatedDate(Date createdDate) {
    this.createdDate = createdDate;
  }

  public String getCommentText() {
    return commentText;
  }

  public void setCommentText(String commentText) {
    this.commentText = commentText;
  }

  @Override
  public int hashCode() {
    return new HashCodeBuilder(11, 37).append(id).toHashCode();
  }

  @Override
  public boolean equals(Object o) {
    if (null == o) return false;
    if (!(o instanceof Issue)) return false;
    if (this == o) return true;

    Issue input = (Issue) o;
    return new EqualsBuilder()
        .append(this.getId(), input.getId())
        .isEquals();

  }

  @Override
  public String toString() {
    return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
        .append(id)
        .toString();
  }

}
